package com.big_data.main.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big_data.main.model.dao.OriginalCovid19MapWangyi;
import com.big_data.main.mapper.OriginalCovid19MapWangyiMapper;
import com.big_data.main.model.vo.AreaDataVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author z2l2y
* @description 针对表【original_covid19_map_wangyi】的数据库操作Service实现
* @createDate 2022-05-16 22:24:36
*/
@Service
public class OriginalCovid19MapWangyiServiceImpl extends ServiceImpl<OriginalCovid19MapWangyiMapper, OriginalCovid19MapWangyi>
    implements OriginalCovid19MapWangyiService, MapService{

    @Override
    public List<OriginalCovid19MapWangyi> getDataMapForAreaForId(Integer id) {
        LambdaQueryWrapper<OriginalCovid19MapWangyi> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id == null) {
            lambdaQueryWrapper.isNull(OriginalCovid19MapWangyi::getParentAddressId);
        } else {
            lambdaQueryWrapper.eq(OriginalCovid19MapWangyi::getParentAddressId, id);
        }
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<OriginalCovid19MapWangyi> getDataMapForAreaForAddressName(String addressName) {
        LambdaQueryWrapper<OriginalCovid19MapWangyi> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(OriginalCovid19MapWangyi::getAddressName, addressName);
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<OriginalCovid19MapWangyi> getDataMapForAreaForAddressNameEn(String addressNameEn) {
        LambdaQueryWrapper<OriginalCovid19MapWangyi> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(OriginalCovid19MapWangyi::getAddressNameEn, addressNameEn);
        return this.list(lambdaQueryWrapper);
    }


    @Override
    public AreaDataVo getMapInfoForAreaForId(Integer id) {
        LambdaQueryWrapper<OriginalCovid19MapWangyi> infoByIdWrapper = new LambdaQueryWrapper<>();
        infoByIdWrapper.eq(OriginalCovid19MapWangyi::getId,id);
        OriginalCovid19MapWangyi tmp = null;
        AreaDataVo res = new AreaDataVo();
        if (id != null && !id.equals(0)) {
            tmp = this.getOne(infoByIdWrapper);
        } else {
            tmp = baseMapper.getInfoForWord();
        }
        BeanUtils.copyProperties(tmp, res);
        return res;
    }

    @Override
    public List<OriginalCovid19MapWangyi> getMapTopForAreaId(Integer id, int num) {
        LambdaQueryWrapper<OriginalCovid19MapWangyi> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id == null) {
            lambdaQueryWrapper.isNull(OriginalCovid19MapWangyi::getParentAddressId);
        } else {
            lambdaQueryWrapper.eq(OriginalCovid19MapWangyi::getParentAddressId, id);
        }
        lambdaQueryWrapper.orderByDesc(OriginalCovid19MapWangyi::getTotalConfirm).last("limit " + num);
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<OriginalCovid19MapWangyi> getMapTopOrderByCurrForAreaId(Integer id, int num) {
        if (id == null) {
            return baseMapper.getMapTopForWord();
        } else {
            return baseMapper.getMapTopForAreaId(id);
        }
    }
}




